package com.scnb.Strategy;

public class Sorter<T> {
    public static void sort(int[] arr){
        for (int i = 0; i < arr.length; i++){
            for (int j = i + 1; j < arr.length; j++){
                if (arr[i] > arr[j]){
                    swap(arr, i, j);
                }
            }
        }
    }

    public static void sort(Cat[] arr){
        for (int i = 0; i < arr.length; i++){
            for (int j = i + 1; j < arr.length; j++){
                if (arr[i].compareTo(arr[j]) > 0){
                    swap(arr, i, j);
                }
            }
        }
    }

    public void sort(T[] arr, Comparator<T> comparator){
        for (int i = 0; i < arr.length; i++){
            for (int j = i + 1; j < arr.length; j++){
                if (comparator.compare(arr[i], arr[j]) > 0){
                    swap(arr, i, j);
                }
            }
        }
    }

    private void swap(T[] arr, int i, int j){
        T tmp;
        tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    private static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    private static void swap(Cat[] arr, int i, int j) {
        Cat tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}
